<template>
	<view>
		<dsl-navbar title='发布反馈意见' isBack  @rightSubmit='rightSubmit'></dsl-navbar>
		<view class="bg-white margin-top-sm">
			<textarea value=""  placeholder="请输入话题内容" class="padding solid-bottom" v-model="introduce" style="width: 90%;height: 100rpx;" />
			<textarea value=""  placeholder="添加正文" class="padding solid-bottom" v-model="introduce" style="width: 90%;height: 100rpx;" />
			<view class="cu-form-group">
				<view class="grid col-4 grid-square flex-sub">
					<view class="bg-img" v-for="(item,index) in upImgList" :key="index" :data-url="upImgList[index]"
						@click.stop="previewImages(index,upImgList)">
						<image :src="upImgList[index]" mode="aspectFill"></image>
						<view class="cu-tag bg-red" @tap.stop="DelImg(index)" :data-index="index">
							<text class='cuIcon-close'></text>
						</view>
					</view>
					<view class="solids" @tap="ChooseImage" v-if="upImgList.length<9">
						<text class='cuIcon-cameraadd'></text>
					</view>
				</view>
			</view>
		</view>
		<view class="padding text-center page-bg round text-white margin " @click="profile">
			保存
		</view>
	</view>
</template>

<script>
	import {setDiscusspublish,upload} from '@/common/path.js'
	export default {
		data() {
			return {
				upImgList: [],//渲染
				upImgs: [], //中间
				introduce:"",
				images:'',//传接口的
			}
		},
		onLoad() {
			setTimeout(r=>{
				// window.location.reload()
			},3000)
		},
		methods: {
			
			//提交发布
			rightSubmit(){
				
			},
			
			ChooseImage() {
				uni.chooseImage({
					count: 9,
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: (event) => {
						uni.showLoading({
							'title': '上传中...'
						})
						event.tempFilePaths.forEach(item => {
							uni.uploadFile({
								url: upload,
								filePath: item,
								name: 'file',
								formData: {
									token: uni.getStorageSync('token'),
								},
								success: (res) => {
									let analysisImg = JSON.parse(res.data)
									this.upImgList.push(analysisImg.data.fullurl)
									this.upImgs.push(analysisImg.data.url)
									let img = this.upImgs.join(',')
									this.images = img
									uni.hideLoading()
								},
								complete() {
									uni.hideLoading()
								}

							})
						})

					}
				})
			},
			DelImg(e) {
				uni.showModal({
					title: '温馨提示',
					content: '确定要删除该图片吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.upImgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			submit(){
				if(this.images ==""){
					this.$tools.showToast('请上传图片')
					return 
				}
				if(this.introduce ==""){
					this.$tools.showToast('请填写内容')
					return 
				}
				let data ={
					images:this.images,
					content:this.introduce
				}
				this.$axios.axios("POST",setDiscusspublish,data)
				.then((res)=>{
					console.log('[发布]',res);
					if(res.code == 1){
						this.$tools.showToast2('已提交审核')
						setTimeout(t=>{
							this.$tools.back()
						},2000)
					}else{
						this.$tools.showToast(res.msg)
					}
				})
			}
		}
	}
</script>

<style>
	.page-bg{
		background-color: #FFA200;
	}
</style>
